//package com.sporch.event;
//
//
//import com.sporch.project.SporchECF;
//import com.sporch.project.SporchEvent;
//import com.sporch.Util;
//import org.junit.Test;
//import org.junit.runner.RunWith;
//import org.kaaproject.kaa.client.DesktopKaaPlatformContext;
//import org.kaaproject.kaa.client.Kaa;
//import org.kaaproject.kaa.client.KaaClient;
//import org.kaaproject.kaa.client.event.EventFamilyFactory;
//import org.kaaproject.kaa.client.event.registration.UserAttachCallback;
//import org.kaaproject.kaa.client.logging.strategies.RecordCountLogUploadStrategy;
//import org.kaaproject.kaa.common.endpoint.gen.UserAttachResponse;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.test.context.junit4.SpringRunner;
//
//import java.io.IOException;
//import java.util.concurrent.Executors;
//import java.util.concurrent.ScheduledExecutorService;
//
//@RunWith(SpringRunner.class)
//@SpringBootTest
//public class ReceiveMessage {
//	private static KaaClient kaaClient;
//
//	private static ScheduledExecutorService scheduledExecutorService;
//	@Test
//	public void contextLoads() {
//		scheduledExecutorService = Executors.newScheduledThreadPool(1);
//
//		// Create the Kaa desktop context for the application.
//		final DesktopKaaPlatformContext desktopKaaPlatformContext = new DesktopKaaPlatformContext();
//		kaaClient = Kaa.newClient(desktopKaaPlatformContext, new FirstKaaClientStateListener(), true);
//
//		/*
//		 *  Used by log collector on each adding of the new log record in order to check whether to send logs to server.
//		 *  Start log upload when there is at least one record in storage.
//		 */
//		RecordCountLogUploadStrategy strategy = new RecordCountLogUploadStrategy(1);
//		strategy.setMaxParallelUploads(1);
//		kaaClient.setLogUploadStrategy(strategy);
//
//		kaaClient.start();
//
//		consumeEvents();
//
//		System.out.println("--= Press any key to exit =--");
//		try {
//			System.in.read();
//		} catch (final IOException e) {
//			System.out.println("IOException has occurred: {}" + e.getMessage());
//		}
//		System.out.println("Stopping Event Consumer...");
//		scheduledExecutorService.shutdown();
//		kaaClient.stop();
//	}
//
//	public void consumeEvents() {
//		//将端点附加给用户
//		kaaClient.attachUser("888888", Util.getMD5("SPORCH_888888")+"_84258741670282877186", new UserAttachCallback() {
//			@Override
//			public void onAttachResult(final UserAttachResponse response) {
//				System.out.println("Attach response: " + response.getResult() +" Reason:"+ response.getErrorReason());
//			}
//		});
//
//
//		final EventFamilyFactory eventFamilyFactory = kaaClient.getEventFamilyFactory();
//		SporchECF sporchECF = eventFamilyFactory.getSporchECF();
//
//		sporchECF.addListener(new SporchECF.Listener() {
//			@Override
//			public void onEvent(SporchEvent event, String source) {
//				System.err.println("消息来了");
//				System.err.println(event+"======="+source);
//				//记录日志
//				kaaClient.addLogRecord(event);
//			}
//		});
//
//	}
//
//}
